import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import eslint from 'vite-plugin-eslint';
import { viteMockServe } from 'vite-plugin-mock';

// import path from 'path'

// https://vitejs.dev/config/
export default defineConfig(({ command }) => {
  return {
    base: './',
    plugins: [
      vue(),
      eslint({
        cache: false,
        include: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.vue'],
        exclude: ['node_modules'],
      }),
      viteMockServe({
        mockPath: 'mock', // mock文件夹路径
        localEnabled: command === 'serve', // 开发打包开关
        prodEnabled: false, // 生产打包开关
        supportTs: true, // 打开后，可以读取 ts 文件模块。 请注意，打开后将无法监视.js 文件。
        watchFiles: true, // 监视文件更改
      }),
    ],
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@import "@/styles/baseMixin.scss";`,
        },
      },
    },
    server: {
      port: 8001,
      host: true,
      proxy: {
        '/api': {
          target: 'http://127.0.0.1',
          changeOrigin: true,
        },
      },
    },
    resolve: {
      alias: [
        {
          find: '@',
          replacement: '/src',
        },
      ],
      extensions: ['.ts', '.js', '.vue'],
    },
    build: {
      outDir: 'dist/test',
      sourcemap: false,
      minify: 'terser',
      terserOptions: {
        compress: {
          drop_console: true,
          drop_debugger: true,
        },
      },
    },
  };
});
